package matrix;

import org.junit.Test;

/**
 * @className: matrix.LeetCode_48
 * @Description: ...
 * @author: kunkun
 * @date: 2025/3/19 21:33
 */
public class LeetCode_48 {

    @Test
    public void test(){
        rotate(new int[][]{{1,2,3},{4,5,6},{7,8,9}});
    }

    public void rotate(int[][] matrix) {
        //1. 矩阵转换
        int l=0,r = matrix.length-1;
        while (l<r){
            int[] temp = matrix[l];
            matrix[l]= matrix[r];
            matrix[r] =temp;
            l++;r--;
        }

        //2. 按照对角线交换
        for (int i = 0; i < matrix.length; i++) {
            for (int j = i+1; j < matrix[i].length; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }

    }


}
